/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import dao.ScheduleDataDao;
import java.sql.Connection;
import java.util.Vector;
import pojo.CMST;
import pojo.LiveServers;
import pojo.MyLST;
import pojo.Scheduledata;

/**
 *
 * @author javauser
 */

//class that handles schedule task operations...
public class ScheduledTaskOperations 
{
    public static void main(String[] args) 
    {
    }
    
    private Connection c;
    private ScheduledTaskWindows windowsTask;
    private ScheduledTaskLinux linuxTask;

    public ScheduledTaskOperations(Connection c) 
    {
        this.c = c;
    }

    //method to create schedule task
    public void create(Scheduledata data, String providername) 
    {
        if (OSDetector.isWindows()) 
        {
            windowsTask = new ScheduledTaskWindows(this.c);
            windowsTask.create(data, providername);
        }
        if (OSDetector.isUnix()) 
        {
            linuxTask = new ScheduledTaskLinux(this.c);
            linuxTask.create(data, providername);
        }
    }

    //method to retreive schedule task
    public Vector<Scheduledata> getAllTasks() 
    {
        ScheduleDataDao dao = new ScheduleDataDao(c);
        return dao.getall();
    }

    //method to enable schedule task
    public void enable(int taskid) 
    {
        if (OSDetector.isWindows()) 
        {
            windowsTask.enable(taskid);
        }
        if(OSDetector.isUnix())
        {
            linuxTask.enable(taskid);
        }
    }

    //method to disable schedule task
    public void disable(int taskid) 
    {
        if (OSDetector.isWindows()) 
        {
            windowsTask.disable(taskid);
        }
        if(OSDetector.isUnix())
        {
            linuxTask.disable(taskid);
        }
    }

    //method to start schedule task
    public void start(int taskid) 
    {
        if (OSDetector.isWindows()) 
        {
            windowsTask.start(taskid);
        }
        if(OSDetector.isUnix())
        {
            linuxTask.start(taskid);
        }
    }

    //this method to delete schedule task
    public boolean delete(int taskid) 
    {
        boolean check=false;
        if (OSDetector.isWindows()) 
        {
            check=windowsTask.delete(taskid);
        }
        if(OSDetector.isUnix())
        {
            check=linuxTask.delete(taskid);
        }
        return check;
    }

    //method to create main schedule task
    public void createmaintask(CMST cmst, String string) 
    {
        if (OSDetector.isWindows()) 
        {
            windowsTask.createmaintask(cmst, string);
        }
        if(OSDetector.isUnix())
        {
            linuxTask.createmaintask(cmst,string);
        }
    }

    //method to create live server schedule task
    public void createLiveServerTask(MyLST lst, LiveServers ls) 
    {
        if (OSDetector.isWindows()) 
        {
            windowsTask.createLiveServerTask(lst, ls);
        }
        if(OSDetector.isUnix())
        {
            linuxTask.createLiveServerTask(lst,ls);
        }
    }

    //method to delete live server schedule task
    public void deleteLiveServerTask(Integer lstId) 
    {
        if (OSDetector.isWindows()) 
        {
            windowsTask.deleteLiveServerTask(lstId);
        }
        if(OSDetector.isUnix())
        {
            linuxTask.deleteLiveServerTask(lstId);
        }
    }

    //method to delete main task
    public void deleteMainTask(String taskName) 
    {
        if (OSDetector.isWindows()) 
        {
            windowsTask.deleteMainTask(taskName);
        }
        if(OSDetector.isUnix())
        {
            linuxTask.deleteMainTask(taskName);
        }
    }
}
